import Circle from "./GameCirclet"

export default class Grade extends Laya.Sprite {

    public secondC
    public thirdC
    public fourthC
    public fifthC
    public sixthC
    public seventhC
    public eighthC
    public lv
    public isClear: boolean = false

    constructor() {
        super()
        Laya.stage.once("clear", this, this.clear)
        Laya.stage.once("rotate", this, this.rotate)

    }
    firstGrade(x: number, y: number, r: number) {//难度一
        let circle = new Circle()
        let c
        this.lv = 1
        c = circle.circle(x, y, r);
        return c
    }
    secondGrade(x: number, y: number, r: number) {//难度二
        let circle = new Circle()
        this.secondC = circle.circle(x, y, r, 32.5, 327.5);
        this.lv = 2
        Laya.timer.frameLoop(1, this, this.rotateAni);
        return this.secondC
    }
    thirdGrade(x: number, y: number, r: number) {//三
        let circle = new Circle()
        this.thirdC = circle.circle(x, y, r, 30, 330);
        this.lv = 3
        Laya.timer.frameLoop(1, this, this.rotateAni);
        return this.thirdC
    }
    fourthGrade(x: number, y: number, r: number) {//四
        let circle = new Circle()
        this.fourthC = circle.circle(x, y, r, 27.5, 332.5);
        this.lv = 4
        Laya.timer.frameLoop(1, this, this.rotateAni);
        return this.fourthC
    }
    fifthGrade(x: number, y: number, r: number) {//五
        let circle = new Circle()
        this.fifthC = circle.circle(x, y, r, 25, 335);
        this.lv = 5
        Laya.timer.frameLoop(1, this, this.rotateAni);
        return this.fifthC
    }
    sixthGrade(x: number, y: number, r: number) {//六
        let circle = new Circle()
        this.sixthC = circle.circle(x, y, r, 22.5, 337.5);
        this.lv = 6
        Laya.timer.frameLoop(1, this, this.rotateAni);
        return this.sixthC
    }
    seventhGrade(x: number, y: number, r: number) {//七
        let circle = new Circle()
        this.seventhC = circle.circle(x, y, r, 20, 340);
        this.lv = 7
        Laya.timer.frameLoop(1, this, this.rotateAni);
        return this.seventhC
    }
    eighthGrade(x: number, y: number, r: number) {//八
        let circle = new Circle()
        this.eighthC = circle.circle(x, y, r, 17.5, 342.5);
        this.lv = 8
        Laya.timer.frameLoop(1, this, this.rotateAni);
        return this.eighthC
    }


    rotateAni(): void {
        if (!this.isClear) {
            if (this.lv == 2) {
                this.secondC.rotation += 1.15
            } else if (this.lv == 3) {
                this.thirdC.rotation += 1.25
            } else if (this.lv == 4) {
                this.fourthC.rotation += 1.35
            } else if (this.lv == 5) {
                this.fifthC.rotation += 1.45
            } else if (this.lv == 6) {
                this.sixthC.rotation += 1.5
            } else if (this.lv == 7) {
                this.seventhC.rotation += 1.6
            } else if (this.lv == 8) {
                this.eighthC.rotation += 1.8
            }
        }

    }

    clear() {
        Laya.timer.clear(this, this.rotateAni)
        this.isClear = true
    }

    rotate() {
        Laya.timer.frameLoop(1, this, this.rotateAni);
        this.isClear = false
    }
}